#include<bits/stdc++.h>
using namespace std;
int n,t;
const int maxn=200005;
int ways[3];
int visited[maxn],dist[maxn];
long long ans=0;
struct point{
    int color,w;
}a[maxn];
inline void score(){
    long long total=0;
    for(int i=n;i>1;i--){
        bool flag=false;
        for(int j=i-1;j>=1;j--){
            if (a[j].color ==a[i].color){
                    flag=true;
                if (a[j].w ==a[i].w ){
                    dist[i]=a[j].w ;
                }
                else{
                    dist[i] =0;
                }
                break;
            }
        }
        if (!flag) dist[i] =0;
        total+=dist[i];
    }
    ans=max(ans,total);
}
inline bool judge(int x){
    bool flag=true;
    if (visited[x]){
        flag=false;
    }
    return flag;
}
void dfs(int x){
    if (x==n+1){
        score();
    }
    else{
        for(int i=1;i<=n;i++){
            for(int j=1;j<=2;j++){
                if (judge(i)){
                    visited[i]=1;
                    a[x].color=ways[j];
                    dfs(x+1);
                    visited[i]=0;
                }
            }
        }
    }
}
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    ways[1]=1;
    ways[2]=2;
    cin>>t;  //t groups of data
    for(int i=1;i<=t;i++){
        memset(visited,0,sizeof(visited));
        memset(dist,0,sizeof(dist));
        ans=0;
        cin>>n;  //number of points
        for(int i=1;i<=n;i++){
            cin>>a[i].w ;
            a[i].color=0;
        }
        dfs(1);
        cout<<ans<<endl;
    }
    fclose(stdin);
    fclose(stdout);
    return 0;
}
